<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\api\model\goods\Goods as GoodsModel;
use think\Request;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    protected $category_model = null;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->category_model = model('app\common\model\Category');
    }

    /**
     * 首页
     *
     */
    public function index()
    {
        header('Access-Control-Allow-Origin:*');
        $banner = $this->category_model
            ->field('image,type,nickname,flag,keywords')
            ->where('type', '=', 'index')
            ->where('nickname','=', 'banner')
            ->select();
        $category = $this->category_model
            ->where('type', '=', 'index')
            ->where('nickname','=', 'category')
            ->select();
            $banner_best = $this->category_model
            ->field('image,type,name,nickname,flag,keywords')
            ->where('type', '=', 'index')
            ->where('nickname','=', 'banner_best')
            ->select();

        $model = new GoodsModel;
        $best = $model->with(['spec'])->where('is_best',1)->limit(10)->select();
        $hot = $model->where('is_hot',1)->limit(3)->select();
        $recommend = $model->where('is_recommend',1)->select();
        $benefit = $model
	        ->with(['spec'])
	        ->where('is_benefit',1)
	        ->limit(3)->select();
        $new = $model->with(['spec'])->where('is_new',1)->select();
        $this->success('请求成功', ['banner' => $banner, 'category' => $category, 'banner_best' => $banner_best, 'best' => $best, 'recommend' => $recommend, 'new' => $new,'hot' => $hot, 'benefit' => $benefit]);
    }
}
